﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Configuration;
using System.Data;
namespace WebSys.UI.Control.ZhengShou
{
    public class EditProjectFWControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        protected MPCalendar 冻结期限开始;
        protected MPCalendar 冻结期限结束;

        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            MPPersistence Persistence1 = (MPPersistence)FindControl("Persistence1");
            Panel ShowProDongjie = (Panel)FindControl("ShowProDongjie");
            TextBox txtID = (TextBox)FindControl("txtID");
            冻结期限开始 = (MPCalendar)FindControl("cal冻结期限开始");
            冻结期限结束 = (MPCalendar)FindControl("txt冻结期限结束");
            if (!base.Page.IsPostBack)
            {
                Persistence1.Table = "ZS_PROJECT";
                Persistence1.Key = "ID";
                Persistence1.KeyValue = HttpContext.Current.Request["pid"];
                Persistence1.ConnStr = _EluZSDataProvider.GetConnectionString();
            }
            Persistence1.BindControl = ShowProDongjie;
            BindData();
            IsLookPerson();
        }

        private void IsLookPerson()
        {
            string sql = "Select rolename from zs_role where id in (Select roleid from zs_user_in_role where userid = '" + userid + "')";
            DataTable dt = _EluZSDataProvider.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["rolename"].ToString().Equals("查看人员"))
                    {
                        Button btnSave = (Button)FindControl("btnSave");
                        btnSave.Visible = true;
                    }
                }
            }
        }

     
        
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            Panel ShowProDongjie = (Panel)FindControl("ShowProDongjie");
            EluZSProvider.Project project = _EluZSDataProvider.GetProjectXX(HttpContext.Current.Request["PID"].ToString());
            TextBox txt申请单位 = (TextBox)ShowProDongjie.FindControl("txt申请单位");
            TextBox txt冻结征收范围 = (TextBox)ShowProDongjie.FindControl("txt冻结征收范围");
            if (string.IsNullOrEmpty(txt申请单位.Text.Trim())) { txt申请单位.Text = project.征收部门; }
            if (string.IsNullOrEmpty(txt冻结征收范围.Text.Trim())) { txt冻结征收范围.Text = project.征收范围; }
        }
        protected void BindData() {
            string pid = HttpContext.Current.Request["pid"];

            Button btnSave = (Button)FindControl("btnSave");
            LinkButton LinkButton1 = (LinkButton)FindControl("LinkButton1");
            btnSave.Click += new EventHandler(btnSave_Click);
            LinkButton1.Click += new EventHandler(LinkButton1_Click);

            if (!_EluZSDataProvider.IsNetZSAdmin(userid) && !_EluZSDataProvider.IsZSAdmin(userid) && !_EluZSDataProvider.IsSZSB(userid))
            {
                LinkButton1.Visible = false;
            }
            Label showhxmsg = (Label)FindControl("showhxmsg");
            string jsstrIP = HttpContext.Current.Request.ServerVariables["HTTP_HOST"];
            if (jsstrIP == ConfigurationManager.AppSettings["zsgis"].ToString())
            {
                
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "displaytr", "<script>displaytr();</script>");
            }
        }
        protected void Bind() {
            TextBox txt冻结征收范围 = (TextBox)FindControl("txt冻结征收范围");
            TextBox txt申请单位 = (TextBox)FindControl("txt申请单位");
            EluZSProvider.Project project = _EluZSDataProvider.GetProjectXX(HttpContext.Current.Request["PID"].ToString());
            txt冻结征收范围.Text = project.征收范围;
            txt申请单位.Text = project.征收部门;
        }
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            HttpContext.Current.Response.Redirect("ZhengSFWLog.aspx?type=1&pid=" + HttpContext.Current.Request["PID"]);
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            
            if (!string.IsNullOrEmpty(冻结期限开始.Text) && string.IsNullOrEmpty(冻结期限结束.Text))
            {
                string [] split = 冻结期限开始.Text.Split('-');
                冻结期限结束.Text = (Convert.ToInt32(split[0]) + 1).ToString() + "-" + split[1].ToString() + "-" + split[2].ToString();
            }
            MPPersistence Persistence1 = (MPPersistence)FindControl("Persistence1");
            Persistence1.Update();
            TextBox txtID = (TextBox)FindControl("txtID");
            //HttpContext.Current.Response.Redirect("EditProjectFW.aspx?PID=" + Persistence1.KeyValue);
            string url = "EditProjectFW.aspx?PID=" + Persistence1.KeyValue;
            base.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('保存成功');location.href='" + url + "'</script>");
        }


    }
}


